package be.humphreys.simplevoronoi;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;

import com.jellyfishumbrella.Site;

public class VoronoiOutput {
	public List<GraphEdge>	allEdges;

	public VoronoiOutput() {
		allEdges = null;
	}
	
	public HashMap<Site, Cell> toCells(){
		HashMap<Site, Cell> cells = new HashMap<Site, Cell>();
		for(int i = 0; i < allEdges.size(); i++){
			GraphEdge currEdge = allEdges.get(i);
			if(!cells.containsKey(currEdge.site1)){
				Cell newCell = new Cell();
				newCell.site = currEdge.site1;
				newCell.edges.add(currEdge);
				cells.put(currEdge.site1,newCell);
			}else{
				Cell currCell = cells.get(currEdge.site1);
				currCell.edges.add(currEdge);
			}
			if(!cells.containsKey(currEdge.site2)){
				Cell newCell = new Cell();
				newCell.site = currEdge.site2;
				newCell.edges.add(currEdge);
				cells.put(currEdge.site2,newCell);
			}else{
				Cell currCell = cells.get(currEdge.site2);
				currCell.edges.add(currEdge);
			}
		}
		return cells;
	}
	
	public String toString(){
		String str = "";
		for(int i = 0; i < allEdges.size(); i++){
			GraphEdge currEdge = allEdges.get(i);
			str += currEdge.toString() + "\n";
		}
		return str;
	}
}
